package com.itheima.bos.service.take_delivery.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.itheima.bos.dao.take_delivery.PromotionRepository;
import com.itheima.bos.domain.page.PageBean;
import com.itheima.bos.domain.take_delivery.Promotion;
import com.itheima.bos.service.take_delivery.PromotionService;

@Service
@Transactional
public class PromotionServiceImpl implements PromotionService {

	@Autowired
	private PromotionRepository promotionService;
	
	@Override
	public void save(Promotion model) {
		promotionService.save(model);
	}

	@Override
	public Page<Promotion> findPageData(Pageable pageable) {
		return promotionService.findAll(pageable);
	}

	@Override
	public PageBean<Promotion> findPageData(Integer page, Integer rows) {
		
		Pageable pageable = new PageRequest(page -1, rows);
		Page<Promotion> pageDate = promotionService.findAll(pageable);
		
		PageBean<Promotion> pageBean = new PageBean<>();
		pageBean.setTotalCount(pageDate.getTotalElements());
		pageBean.setPageData(pageDate.getContent());
		
		return pageBean;
	}

	@Override
	public Promotion findPromotionById(Integer id) {
		
		return promotionService.findOne(id);
	}

	@Override
	public void updatePromotionStauts(Date date) {
		
		promotionService.updatePromotionStauts(date);
	}

}
